import cv2
import numpy as np

def get_hsv_color_range(image_path):
    # 读取图片
    image = cv2.imread(image_path)
    
    if image is None:
        print("Failed to read the image.")
        return
    
    # 将图片转换为 HSV 颜色空间
    hsv_image = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
    
    # 计算 HSV 颜色空间中的最小值和最大值
    h_min, s_min, v_min = np.min(hsv_image, axis=(0, 1))
    h_max, s_max, v_max = np.max(hsv_image, axis=(0, 1))
    
    return (h_min, s_min, v_min), (h_max, s_max, v_max)

# 指定PNG图片路径
image_path = "8.png"

# 获取 HSV 颜色范围
hsv_min, hsv_max = get_hsv_color_range(image_path)
print("HSV Color Range:")
print("Min: ", hsv_min)
print("Max: ", hsv_max)

"""
HSV Color Range:
Min:  (85, 235, 171)
Max:  (93, 255, 212)

Min:  (85, 233, 171)
Max:  (95, 255, 215)

Min:  (85, 255, 180)
Max:  (91, 255, 215)


HSV Color Range:
Min:  (88, 255, 114)
Max:  (88, 255, 114)

age_hsv.py
HSV Color Range:
Min:  (60, 113, 75)
Max:  (69, 255, 206)
"""

